package com.mds.group.four.test;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.EditText;
import android.widget.ImageView;

public class PlayActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.play);
		/* Image 호출. */
		ImageView iv = (ImageView)findViewById(R.id.playImage);
		iv.setImageDrawable(getResources().getDrawable(R.drawable.test6));
		iv.setScaleType(ImageView.ScaleType.FIT_XY);
		
		/* EditText를 이용해서 화면에 출력할 문자 설정. */
		EditText et = (EditText)findViewById(R.id.playtext);
		et.setText("거북이");
	}
	
	/* 터치시 음성 재생. */
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		play(R.raw.ts1);
		return super.onTouchEvent(event);
	}
	
	/** 음성재생 MediaPlayer 메서드 */
	private static MediaPlayer audio_play;
	public void stop() {
		if(audio_play != null) {
			audio_play.stop();
			audio_play.release();
			audio_play = null;
		}
	}
	public void play(int wav) {
		if(audio_play == null || !audio_play.isPlaying()){
		stop();
		audio_play = MediaPlayer.create(this, wav);
		audio_play.setLooping(false);
		audio_play.start();}
	}
}